<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/7/1
 * Time: 8:33 AM
 */
namespace app\common\models;

class NavMenu extends BaseModel
{
    public $table = 'yq_nav_menu';
    public $timestamps = true;
    protected $guarded = [''];

    const HREF_TYPE_URL = 0;//链接类型url
    const HREF_TYPE_CATEGORY = 1;//链接类型分类
    const HREF_TYPE_ARTICLE = 2;//链接类型文章
    const HREF_TYPE_PAGE = 3;//链接类型页面

    public static $hrefTypeMap = [
        self::HREF_TYPE_URL=>'url链接',
        self::HREF_TYPE_CATEGORY=>'分类',
        self::HREF_TYPE_ARTICLE=>'文章',
        self::HREF_TYPE_PAGE=>'页面',
    ];
    public function parent()
    {
        return $this->hasOne(self::class, 'id', 'pid');
    }
    public function children()
    {
        return $this->hasMany(self::class, "pid",'id');
    }
    public static function getById($id){
        return self::site()->select()
            ->where('id',$id)
            ->first();
    }
    public  function atributeNames() {
        return [
            'name'  => '菜单名称',
            'nav_id'  => '导航ID'
        ];
    }

    public  function rules()
    {
        return [
            'name' => 'required',
            'nav_id' => 'required'
        ];
    }
}